package com.lzx.iteam.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.Scroller;

public class ChatListGroup extends LinearLayout{

    Scroller scroller;
    boolean open;
    
    public ChatListGroup(Context context, AttributeSet attrs) {
        super(context, attrs);
        scroller = new Scroller(context);
    }
    
    @Override
    public void computeScroll() {
        super.computeScroll();
        if(scroller.computeScrollOffset()){
            scrollTo(scroller.getCurrX(), scroller.getCurrY());
            postInvalidate();
        }
    }
    
    public void setOpen(boolean open){
        this.open = open;
    }
    
       @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);
        int width = getWidth();
        if(open){
            scrollTo(width/2, 0);
        }
        
    }
    
    public void scrollToOpen(){
        if(!open){
            int width = getWidth();
            scroller.startScroll(getScrollX(),getScrollY(), width/2-getScrollX(), 0-getScrollY(), 500);
            open = true;
            postInvalidate();
        }
    }
    
    public void scrollToHide(){
        if(open){
            scroller.startScroll(getScrollX(),getScrollY(), 0-getScrollX(), 0-getScrollY(), 500);
            open = false;
            postInvalidate();
        }
    }
    

}
